<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/10/18
 * Time: 11:23
 */
namespace Redbag\Controller;
use Api\Controller\BaseApiController;
use Redbag\Model\RedbagModel;
use User\Model\UserModel;
class ApiController extends BaseApiController
{
    private $user_db;
    private $redbag_db;
    private $mid;
    function _initialize()
    {
        parent::_initialize();
        if (!in_array(ACTION_NAME, array('regist', 'login'))) {
            $this->mid = $this->_initUser(I('uid'));
        }
        $this->user_db = new UserModel();
        $this->redbag_db = new RedbagModel();
    }

    /**
     * 发红包
     */
    public function sendRedbag(){
        $return = $this->redbag_db->sendRedbag($this->mid);
        $this->jsonOutput($return);
    }

    /**
     * 抢红包
     */
    public function grabRedbag(){
        $return = $this->redbag_db->grabRedbag($this->mid);
        $this->jsonOutput($return);
    }

    /**
     * 查看红包
     */
    public function catRedbag(){
        $return = $this->redbag_db->catRedbag($this->mid);
        $this->jsonOutput($return);
    }

    /**
     * 发红包记录
     */
    public function sendRedbagList(){
        $return = $this->redbag_db->sendRedbagList($this->mid);
        $this->jsonOutput($return);
    }

    /**
     * 领红包记录
     */
    public function grabRedbagList(){
        $return = $this->redbag_db->grabRedbagList($this->mid);
        $this->jsonOutput($return);
    }

    /**
     * 发给某个人的红包
     */
    public function sendSingleRedbag(){
        $return = $this->redbag_db->sendSingleRedbag($this->mid);
        $this->jsonOutput($return);
    }

    /**
     * 抢某个人发的红包
     */
    public function grabSingleRedbag(){
        $return = $this->redbag_db->grabSingleRedbag($this->mid);
        $this->jsonOutput($return);
    }
}